package com.example.bootrabbitmq.restful;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResultVO<T> {
    private int code;
    private String msg;
    private T data;
    private Long timestamp;

    public ResultVO(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.timestamp = System.currentTimeMillis();
    }

    public ResultVO(int code, String msg) {
        this.code = code;
        this.msg = msg;
        this.data = null;
        this.timestamp = System.currentTimeMillis();
    }

    public ResultVO(ResultCodeEnum resultCode, T data) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
        this.data = data;
        this.timestamp = System.currentTimeMillis();

    }

    public ResultVO(T data) {
        this(ResultCodeEnum.SUCCESS, data);
    }

    public static ResultVO fail(ResultCodeEnum resultCode) {
        return new ResultVO(resultCode.getCode(), resultCode.getMsg());
    }

    public static ResultVO ok(Object data) {
        return new ResultVO(ResultCodeEnum.SUCCESS, data);
    }

    public static ResultVO ok() {
        return new ResultVO(ResultCodeEnum.SUCCESS, null);
    }
}